package com.zerosky.crm.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zerosky.crm.dao.LoginLogDAO;
import com.zerosky.crm.po.LoginLog;
import com.zerosky.crm.service.LoginLogService;
import com.zerosky.crm.util.PageInfo;

@Service(value="loginLogService")
public class LoginLogServiceImpl implements LoginLogService {
	@Autowired
	private LoginLogDAO loginLogDao;

	/**
	 * 分页查询信息
	 */
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public PageInfo<LoginLog> getPageInfoList(Map<String, Object> map) {
		PageInfo<LoginLog> page = new PageInfo<LoginLog>();
		int begin = (((int) map.get("pageNo") - 1) * (int) map.get("pageSize"));
		// 写入数据
		map.put("pageNo", begin);
		List<LoginLog> list = loginLogDao.getLoginLogList(map);
		page.setList(list);
		int count = loginLogDao.countLoginLog(map);// 获取总记录
		page.setPageCount(count);
		return page;
	}

	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public Integer saveOrUpdate(LoginLog service) {
		return loginLogDao.saveLoginLog(service);
	}

}
